using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Security.Permissions;
using System.Text;


namespace ReadFileTest
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            this.readFile();
        }

        private void readFile()
        {
            byte[] fileBytes = null;
            long fileSize = -1;
            Stream fileStream = null;

            //string filename = @"Test.txt";
            //string filename = @"D:\DATA\UsercheeOnD\myVS2005\IntelTestBed\ReadFile\test.txt";
            string filename = @"H:\myCsharp\BeginningASPnet\ReadFileTest\Test.txt";
            try
            {
//                FileIOPermission ff = new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, filename);     
                filename = Path.GetFullPath(filename);
                TextBox1.Text = filename;
                filename = Path.GetFullPath(filename);
                fileStream = File.OpenRead(filename);
                if (!fileStream.CanRead)
                {
                    throw new Exception("Unable to read from file.");
                }
                fileSize = fileStream.Length;
                fileBytes = new byte[fileSize];
                fileStream.Read(fileBytes, 0, Convert.ToInt32(fileSize));
                string outs = Encoding.ASCII.GetString(fileBytes);
                TextBox1.Text = TextBox1.Text + "\n " + outs;
            }

            catch (System.Exception sss)
            {
                TextBox1.Text = sss.ToString();
            }

        }
    }
}
